package gui.util;

import java.awt.Container;
import java.awt.Dimension;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;

import javax.swing.JFrame;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.swing.JRViewer;

public class Relatorio extends JFrame {
	private static final long serialVersionUID = 1L;

	public Relatorio(String fileName) {
		super(fileName);
		try {
			String driver = "com.mysql.jdbc.Driver";
			String url = "jdbc:mysql://localhost:3306/quiosque";
			String user = "root";
			String password = "root";
			Class.forName(driver);
			Connection con = DriverManager.getConnection(url, user, password);
			JasperPrint print = JasperFillManager.fillReport(fileName, new HashMap<String, Object>(), con);
			JRViewer viewer = new JRViewer(print);
			Container c = getContentPane();
			c.add(viewer);
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
		} catch (SQLException sqle) {
			sqle.printStackTrace();
		} catch (JRException jre) {
			jre.printStackTrace();
		}
		setBounds(10, 10, 800, 600);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		Dimension dim = this.getToolkit().getScreenSize();      
		int x = (int) (dim.getWidth()  - this.getSize().getWidth() ) / 2;
		int y = (int) (dim.getHeight() - this.getSize().getHeight()) / 2;
		this.setLocation(x,y);
	}
}